﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Bean;
using Shpm.App.Commons.Utils;
using Shpm.App.Input.Dao;

public partial class App_Search_HealthWorkStat : System.Web.UI.Page
{
    private const string COMMAND_SEARCH = "DoSearch";

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    #region 检索按钮
    protected void btnSeach_Click(object sender, EventArgs e)
    {
        if (ComValidator1.DoValidator())
        {
            ViewState["TXT_ID"] = txtId.Text.Trim();
            ViewState["TXT_START"] = txtStart.Text.Trim();
            ViewState["TXT_END"] = txtEnd.Text.Trim();
            ViewState["ParamCommand"] = COMMAND_SEARCH;
        }
    }
    #endregion

    #region 读取数据
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        if (COMMAND_SEARCH.Equals(ViewState["ParamCommand"]))
        {
            // 构建检索条件对象
            HealthWorkStatBean dataBean = new HealthWorkStatBean();
            dataBean.EmployeeId = Convert.ToString(ViewState["TXT_ID"]);
            if (Convert.ToString(ViewState["TXT_START"]) != string.Empty)
            {
                dataBean.StartTime = DateUtils.convertToDate(Convert.ToString(ViewState["TXT_START"]));
            }
            if (Convert.ToString(ViewState["TXT_END"]) != string.Empty)
            {
                dataBean.EndTime = DateUtils.convertToDate(Convert.ToString(ViewState["TXT_END"]));
            }
            // 检索结果绑定到控件
            HealthWorkStatDao dao = new HealthWorkStatDao();
            IList dataList = dao.FindByHealthWorkStat(dataBean);
            SumCount(dataList);
            GridView1.DataSource = dataList;
            GridView1.DataBind();

            tblResult.Visible = dataList.Count > 0;
        }
        else
        {
            tblResult.Visible = false;
        }
    }
    #endregion

    #region 统计
    private void SumCount(IList lst)
    {
        int i = 0;
        int j = 0;
        if (lst.Count > 0)
        {
            for (int l = 0; l < lst.Count; l++)
            {
                HealthWorkStatBean dataBean = new HealthWorkStatBean();
                dataBean = (HealthWorkStatBean)lst[l];
                i = i + dataBean.Cnt1;
                j = j + dataBean.Cnt2;
            }
        }
        lbl1.Text = i.ToString();
        lbl2.Text = j.ToString();
    }
    #endregion

    #region GridView1_PageIndexChanging
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 设置分页编号
        GridView1.PageIndex = e.NewPageIndex;
    }
    #endregion
}
